package bjtu.pinet.common;

import org.onlab.packet.BasePacket;
import org.onosproject.net.ConnectPoint;

import java.io.Serializable;

/**
 * author:chushuai
 * date:2021.2.13
 */
public class ParsingResult implements Serializable{
    /*字段类型定义*/
    private static final long serialVersionID = -6193288028931761229L;
    private int networkTypeId;//表示数据包对应的网络模态类型
    private short etherType;//表示数据包的以太网字段
    private BasePacket packetParsingResult;//表示数据包解析后的各字段的结果
    private PrincipalsObject principalsObject;//存储网络主体对象
    private ConnectPoint receiceFrom;
    /*构造方法定义*/
    public ParsingResult(int networkTypeId, short etherType, BasePacket packetParsingResult, PrincipalsObject principalsObject,ConnectPoint receiceFrom) {
        this.networkTypeId = networkTypeId;
        this.etherType = etherType;
        this.packetParsingResult = packetParsingResult;
        this.principalsObject = principalsObject;
        this.receiceFrom = receiceFrom;
    }

    public ConnectPoint getReceiceFrom() {
        return receiceFrom;
    }

    public void setReceiceFrom(ConnectPoint receiceFrom) {
        this.receiceFrom = receiceFrom;
    }

    public int getNetworkTypeId() {
        return networkTypeId;
    }

    public void setNetworkTypeId(int networkTypeId) {
        this.networkTypeId = networkTypeId;
    }

    public short getEtherType() {
        return etherType;
    }

    public void setEtherType(short etherType) {
        this.etherType = etherType;
    }

    public BasePacket getPacketParsingResult() {
        return packetParsingResult;
    }

    public void setPacketParsingResult(BasePacket packetParsingResult) {
        this.packetParsingResult = packetParsingResult;
    }

    @Override
    public String toString() {
        return "  解析结果(ParsingResult){\n" +
                "  网络模态类型:" + "IPv4网络模态\n" +
                "  以太网类型:" + etherType +"\n"+
                "  数据包字段结果:" + packetParsingResult +"\n"+
                "  主体对象:" + principalsObject.toString() +"\n"+
                "  接收数据包位置：" + receiceFrom.toString() + "\n"+
                '}';
    }

    public PrincipalsObject getPrincipalsObject() {
        return principalsObject;
    }

    public void setPrincipalsObject(PrincipalsObject principalsObject) {
        this.principalsObject = principalsObject;
    }

    public static class PrincipalsObject implements Serializable {
        private static final long serialVersionID = -6193288028931761227L;
        private String sourceAddress;
        private String destinationAddress;

        public PrincipalsObject(String sourceAddress, String destinationAddress) {
            this.sourceAddress = sourceAddress;
            this.destinationAddress = destinationAddress;
        }

        public String getSourceAddress() {
            return sourceAddress;
        }

        public void setSourceAddress(String sourceAddress) {
            this.sourceAddress = sourceAddress;
        }

        public String getDestinationAddress() {
            return destinationAddress;
        }

        public void setDestinationAddress(String destinationAddress) {
            this.destinationAddress = destinationAddress;
        }

        @Override
        public String toString() {
            if(sourceAddress.equals(destinationAddress)){
                return "PrincipalsObject{" +"ndnName="+
                        sourceAddress + '\''
                        +'}';
            }else{
                return "PrincipalsObject{" +
                        "sourceAddress='" + sourceAddress + '\'' +
                        ", destinationAddress='" + destinationAddress + '\'' +
                        '}';
            }

        }
    }
}
